package main

import "fmt"

// 抽象工厂模式基于工厂方法模式。两者的区别在于：
// 工厂方法模式是创建出一种产品，而抽象工厂模式是创建出一类产品。
// 这二种都属于工厂模式，在设计上是相似的。

type SaveArticle interface {
	CreateProse() Prose
	CreateAncientPoetry() AncientPoetry
}

type SaveRedis struct{}

func (*SaveRedis) CreateProse() Prose {
	return &RedisProse{}
}
func (*SaveRedis) CreateAncientPoetry() AncientPoetry {
	return &RedisProse{}
}

type SaveMysql struct{}

func (*SaveMysql) CreateProse() Prose {
	return &MysqlProse{}
}

func (*SaveMysql) CreateAncientPoetry() AncientPoetry {
	return &MysqlProse{}
}

type Prose interface {
	SaveProse()
}

type AncientPoetry interface {
	SaveAncientPoetry()
}

type RedisProse struct{}

func (*RedisProse) SaveProse() {
	fmt.Println("redis save prose")
}

func (*RedisProse) SaveAncientPoetry() {
	fmt.Println("redis save ancient poetry")
}

type MysqlProse struct{}

func (*MysqlProse) SaveProse() {
	fmt.Println("mysql save Prose")
}

func (*MysqlProse) SaveAncientPoetry() {
	fmt.Println("mysql save ancient poetry")
}

// 使用
func Save(saveArticle SaveArticle) {
	saveArticle.CreateProse().SaveProse()
	saveArticle.CreateAncientPoetry().SaveAncientPoetry()
}
func ExampleSaveRedis() {
	var factory SaveArticle = &SaveRedis{}
	Save(factory)
}
func ExampleSaveMysql() {
	var factory SaveArticle = &SaveMysql{}
	Save(factory)
}
